package main

import (
	"context"
	"fmt"
	"gitee.com/DonHz/electronic-business-systems/mxshop_srvs/userop_srv/proto"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
)

var (
	userFavClient proto.UserFavClient
	msgClient     proto.MessageClient
	addClient     proto.AddressClient
	conn          *grpc.ClientConn
)

func Init() {
	var err error
	conn, err = grpc.NewClient("127.0.0.1:58739", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		panic("create client connect failed: " + err.Error())
	}
	userFavClient = proto.NewUserFavClient(conn)
	msgClient = proto.NewMessageClient(conn)
	addClient = proto.NewAddressClient(conn)
}

func main() {
	Init()
	defer conn.Close()
	TestGetFavList()
	TestMessageList()
	TestGetAddressList()
}

func TestGetAddressList() {
	resp, err := addClient.GetAddressList(context.Background(), &proto.AddressRequest{
		UserId: 1,
	})
	if err != nil {
		panic(err)
	}
	fmt.Println(resp.Data)
	fmt.Println(resp.Total)
}

func TestMessageList() {
	resp, err := msgClient.MessageList(context.Background(), &proto.MessageRequest{
		UserId: 1,
	})
	if err != nil {
		panic(err)
	}
	fmt.Println(resp.Data)
	fmt.Println(resp.Total)
}

func TestGetFavList() {
	resp, err := userFavClient.GetFavList(context.Background(), &proto.UserFavRequest{
		UserId: 1,
	})
	if err != nil {
		panic(err)
	}
	fmt.Println(resp.Data)
	fmt.Println(resp.Total)
}
